import {createRouter, createWebHistory} from 'vue-router'

import Home from '../views/Home.vue'

const routes = [
    {
        path: '/',
        name: 'Index',
        component: () => import('../views/Index.vue'),
        children:[
            {
                path: '/',
                name: 'Home',
                component: () => import('../views/Home.vue'),
            },
            {
                path: '/home',
                name: 'home',
                component: () => import('../views/Home.vue'),
            },
            {
                path: '/res/',
                name: 'Resource',
                component: () => import('../views/resource/Resource.vue')
            },
            {
                path: '/res/detail/:id',
                name: 'ResourceDetail',
                component: () => import('../views/resource/ResourceDetail.vue')
            },
            {
                path: '/article',
                name: 'Article',
                component: () => import('../views/article/Articles.vue')
            },
            {
                path: '/article/detail/:id',
                name: 'ArticleDetail',
                component: () => import('../views/article/ArticleDetail.vue')
            },
            {
                path: '/signin',
                name: 'SignIn',
                component: () => import('../views/SignIn.vue')
            },
            {
                path: '/signup',
                name: 'SignUp',
                component: () => import('../views/SignUp.vue')
            },
            {
                path: '/about',
                name: 'About',
                component: () => import('../views/About.vue')
            },
            {
                path: '/manage',
                name: 'Manage',
                component: () => import('../views/manage/Manage.vue'),
                children:[
                    {
                        path: '/manage/',
                        name: 'MIndex',
                        component: () => import('../views/manage/Index.vue'),
                    },
                    {
                        path: '/manage/resource',
                        name: 'MResource',
                        component:()=>import('../views/manage/content/Resource.vue'),
                    },
                    {
                        path: '/manage/article',
                        name: 'MArticle',
                        component:()=>import('../views/manage/content/Article.vue'),
                    },
                    {
                        path: '/manage/comment',
                        name: 'MComment',
                        component:()=>import('../views/manage/content/Comment.vue'),
                    },
                    {
                        path: '/manage/group',
                        name: 'MGroup',
                        component:()=>import('../views/manage/content/Group.vue'),
                    },
                    {
                        path: '/manage/user',
                        name: 'MUser',
                        component:()=>import('../views/manage/account/UserInfo.vue'),
                    },
                    {
                        path: '/manage/account',
                        name: 'MAccount',
                        component:()=>import('../views/manage/account/Account.vue'),
                    },
                    {
                        path: '/manage/setting',
                        name: 'MSetting',
                        component:()=>import('../views/manage/Seetting.vue'),
                    },
                    {
                        path: '/share',
                        name: 'Share',
                        component: () => import('../views/resource/ShareResource.vue')
                    },
                    {
                        path: '/manage/update/password',
                        name:'UpdatePassword',
                        component:()=>import('../views/manage/account/UpdatePassword.vue')
                    },
                    {
                        path: '/manage/update/email',
                        name:'UpdateEmail',
                        component:()=>import('../views/manage/account/UpdateEmail.vue')
                    },
                    {
                        path: '/manage/update/phone',
                        name:'UpdatePhone',
                        component:()=>import('../views/manage/account/UpdatePhone.vue')
                    }
                ]
            }
        ]
    },

    {
        path: '/mdeditor',
        name: 'MDEditor',
        component: () => import('../views/editor/MarkdownEditor.vue')
    },
    {
        path: '/resume/:id',
        name: 'Resume',
        component: () => import('../views/user/Resume.vue'),
        children: [
            {
                path: '/resume/:id',
                name: 'ResumeIndex',
                component: () => import('../views/user/Index.vue'),
            },
            {
                path: '/resume/log/:id',
                name: 'ResumeLog',
                component: () => import('../views/user/DayLog.vue'),
            },
            {
                path: '/resume/photo/:id',
                name: 'ResumePhoto',
                component: () => import('../views/user/DayPhoto.vue'),
            },
            {
                path: '/resume/info/:id',
                name: 'ResumeInfo',
                component: () => import('../views/user/UserInfo.vue'),
            },
            {
                path: '/resume/share/:id',
                name: 'ResumeShare',
                component: () => import('../views/user/DayShare.vue'),
            },
        ]
    },
    {
        path: '/:pathMatch(.*)',
        name: '404',
        component:()=>import('../views/error/404.vue')
    }

]

const router = createRouter({
    history: createWebHistory(),
    routes
})

const authList=[
    "/mdeditor",
    "/manage",
    "/share",
]

router.beforeEach((to, from, next) => {
    authList.forEach(i=>{
        if(to.path==i&&localStorage.getItem("auth")==null)
            next("/signin")
    })
    next()
})
export default router
